package com.imooc.freecoding.service.impl;

import com.imooc.freecoding.entity.News;
import com.imooc.freecoding.mapper.NewsMapper;
import com.imooc.freecoding.service.NewsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("newsService")
public class NewsServiceImpl implements NewsService {
    @Resource
    private NewsMapper newsMapper;
    /**
     * 根据id查询news
     *
     * @param id newsId
     * @return news 对象
     */
    @Override
    public News selectById(Long id) {
        News news = newsMapper.selectById(id);
        return news;
    }

    /**
     * 新增新闻
     *
     * @param news 新闻对象
     * @return
     */
    @Override
    public void insertNews(News news) {
        newsMapper.insertNews(news);
    }

    /**
     * 按id删除
     *
     * @param id
     */
    @Override
    public void deleteNews(Long id) {
        newsMapper.deleteNews(id);
    }

    /**
     * 修改
     *
     * @param news
     * @return
     */
    @Override
    public void updateNews(News news) {
        News nowNews = newsMapper.selectById(news.getId());
        nowNews.setContent(news.getContent());
        newsMapper.updateNews(nowNews);
    }
}
